package com.dengyafei.controller;

import com.dengyafei.annotation.JwtToken;
import com.dengyafei.bean.ResumeEntity;
import com.dengyafei.constant.RecommendConstant;
import com.dengyafei.constant.ResultMessage;
import com.dengyafei.domin.vo.*;
import com.dengyafei.result.RedisShareEntity;
import com.dengyafei.result.RestApiResult;
import com.dengyafei.service.ResumeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.zip.DataFormatException;

/**
 * @author 邓亚非
 */
@RestController
@RequestMapping("/resume")
@Slf4j
public class ResumeController {

    @Autowired
    ResumeService resumeService;

    /**
     * 查看简历接口
     *
     * @param resumeQueryByGidVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/viewResume")
    public RestApiResult viewResume(@RequestBody ResumeQueryByGidVO resumeQueryByGidVO) {
        log.info("【简历模块-查看简历接口-参数】resumeQueryByGidVO:[{}]", resumeQueryByGidVO);
        ResumeEntity resumeEntity = resumeService.queryByGid(resumeQueryByGidVO);
        log.info("【简历模块-查看简历接口-成功】resumeQueryByGidVO:[{}]", ResultMessage.Resume.VIEW_RESUME_SUCCESS);
        return RestApiResult.ok(resumeEntity);
    }

    /**
     * 发送面试邮件
     *
     * @param sendEmailVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/sendInterviewEmail")
    public RestApiResult sendInterviewEmail(@RequestBody SendEmailVO sendEmailVO) throws DataFormatException {
        log.info("【简历模块-发送面试邮件接口-参数】sendEmailVO:[{}]", sendEmailVO);
        Boolean aBoolean = resumeService.sendInterviewEmail(sendEmailVO);
        if (!aBoolean.equals(true)) {
            log.error("【简历模块-发送面试邮件接口-失败】sendEmailVO,cause:[{}]", ResultMessage.Resume.SEND_INTERVIEW_EMAIL_FAILURE);
            return RestApiResult.error(ResultMessage.Resume.SEND_INTERVIEW_EMAIL_FAILURE);
        }
        log.info("【简历模块-发送面试邮件接口-成功】sendEmailVO:[{}]", ResultMessage.Resume.SEND_INTERVIEW_EMAIL_SUCCESS);
        return RestApiResult.okMsg(ResultMessage.Resume.SEND_INTERVIEW_EMAIL_SUCCESS);
    }

    /**
     * 发送录用邮件接口
     *
     * @param resumeApplyVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/sendApplyEmail")
    public RestApiResult sendApplyEmail(@RequestBody ResumeApplyVO resumeApplyVO) {
        log.info("【简历模块-发送录用邮件接口-参数】resumeApplyVO:[{}]", resumeApplyVO);
        Boolean aBoolean = resumeService.sendApplyEmail(resumeApplyVO);
        if (!aBoolean) {
            log.error("【简历模块-发送录用邮件接口-失败】resumeApplyVO,cause[{}]", ResultMessage.Resume.SEND_INTERVIEW_EMAIL_FAILURE);
            return RestApiResult.error(ResultMessage.Resume.SEND_INTERVIEW_EMAIL_FAILURE);
        }
        log.info("【简历模块-发送录用邮件接口-成功】resumeApplyVO:[{}]", ResultMessage.Resume.SEND_INTERVIEW_EMAIL_SUCCESS);
        return RestApiResult.okMsg(ResultMessage.Resume.SEND_INTERVIEW_EMAIL_SUCCESS);
    }

    /**
     * 分享求职经验接口
     *
     * @param shareVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/share")
    public RestApiResult share(@RequestBody ShareVO shareVO) {
        log.info("【简历模块-分享求职经验接口-参数】shareVO:[{}]", shareVO);
        Boolean aBoolean = resumeService.addShare(shareVO);
        if (!aBoolean) {
            log.error("【简历模块-分享求职经验接口-失败】shareVO,cause:[{}]", ResultMessage.Resume.SHARE_FAILURE);
            return RestApiResult.error(ResultMessage.Resume.SHARE_FAILURE);
        }
        log.info("【简历模块-分享求职经验接口-成功】shareVO:[{}]", ResultMessage.Resume.SHARE_SUCCESS);
        return RestApiResult.okMsg(ResultMessage.Resume.SHARE_SUCCESS);
    }

    /**
     * 查询所有分享接口
     *
     * @return
     */
    @JwtToken
    @PostMapping(value = "/queryAllShare")
    public RestApiResult queryAllShare() {
        log.info("【简历模块-查询所有分享接口-参数】:[{}]", "无参");
        List<RedisShareEntity> redisShareEntities = resumeService.queryAllShare();
        log.info("【简历模块-查询所有分享接口-成功】:[{}]", ResultMessage.Resume.VIEW_RESUME_SUCCESS);
        return RestApiResult.ok(redisShareEntities);
    }

    /**
     * 删除分享接口
     *
     * @param resumeDeleteShareVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/deleteOneShare")
    public RestApiResult deleteOneShare(@RequestBody ResumeDeleteShareVO resumeDeleteShareVO) {
        log.info("【简历模块-删除分享接口-参数】resumeDeleteShareVO:[{}]", resumeDeleteShareVO);
        Boolean aBoolean = resumeService.deleteShare(resumeDeleteShareVO);
        if (!aBoolean) {
            log.error("【简历模块-删除分享接口-失败】resumeDeleteShareVO,cause:[{}]", ResultMessage.Resume.DELETE_FAILURE);
            return RestApiResult.error(ResultMessage.Resume.DELETE_FAILURE);
        }
        log.info("【简历模块-删除分享接口-成功】resumeDeleteShareVO:[{}]", ResultMessage.Resume.DELETE_SUCCESS);
        return RestApiResult.okMsg(ResultMessage.Resume.DELETE_SUCCESS);
    }

    /**
     * 查询简历接口
     *
     * @return
     */
    @JwtToken
    @PostMapping(value = "/queryResumeByGid")
    public RestApiResult queryResumeByGid() {
        log.info("【简历模块-查询个人简历接口-参数】:[{}]", "无参");
        ResumeEntity resumeEntity = resumeService.queryResumeByGid();
        log.info("【简历模块-查询个人简历接口-成功】:[{}]", ResultMessage.Resume.QUERY_SUCCESS);
        return RestApiResult.ok(resumeEntity);
    }

    /**
     * 添加简历
     *
     * @param resumeAddVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/addResume")
    public RestApiResult addResume(@RequestBody ResumeAddVO resumeAddVO) {
        log.info("【简历模块-添加简历接口-参数】:[{}]", resumeAddVO);
        Integer integer = resumeService.insertResume(resumeAddVO);
        if (!integer.equals(RecommendConstant.OPERATION_SUCCESS)) {
            log.error("【简历模块-添加简历接口-失败】resumeAddVO,cause:[{}]", ResultMessage.Resume.ADD_RESUME_FAILURE);
            return RestApiResult.error(ResultMessage.Resume.ADD_RESUME_FAILURE);
        }
        log.info("【简历模块-添加简历接口-成功】resumeAddVO:[{}]", ResultMessage.Resume.ADD_RESUME_SUCCESS);
        return RestApiResult.okMsg(ResultMessage.Resume.ADD_RESUME_SUCCESS);
    }

    /**
     * 更新简历
     *
     * @param resumeUpdateVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "updateResume")
    public RestApiResult updateResume(@RequestBody ResumeUpdateVO resumeUpdateVO) {
        log.info("【简历模块-更新简历接口-参数】resumeUpdateVO:[{}]", resumeUpdateVO);
        Integer integer = resumeService.updateResume(resumeUpdateVO);
        if (!integer.equals(RecommendConstant.OPERATION_SUCCESS)) {
            log.error("【简历模块-更新简历接口-失败】resumeAddVO,cause:[{}]", ResultMessage.Resume.UPDATE_RESUME_FAILURE);
            return RestApiResult.error(ResultMessage.Resume.UPDATE_RESUME_FAILURE);
        }
        log.info("【简历模块-更新简历接口-成功】resumeAddVO:[{}]", ResultMessage.Resume.UPDATE_RESUME_SUCCESS);
        return RestApiResult.okMsg(ResultMessage.Resume.UPDATE_RESUME_SUCCESS);
    }
}